﻿using System.Collections.Generic;
using System.Linq;

namespace Project5188.BUS.DocumentManagement
{
    public class DocumentTypeRelation : DetailView<documenttyperelation>
    {
        private project5188Entities _context;
        // ReSharper disable InconsistentNaming
        private new List<documenttyperelation> EntityList;
        private new documenttyperelation Entity;
        // ReSharper restore InconsistentNaming

        public long TransactionId { get; private set; }

        #region Overrides of DetailView<documenttyperelation>

        public override List<documenttyperelation> GetEntityList()
        {
            _context = new project5188Entities();
            EntityList = _context.documenttyperelations.Where(a => !a.IsDeleted).OrderBy(a => a.a_ID).ToList();

            return EntityList;
        }

        public override List<documenttyperelation> GetEntityById(long id)
        {
            _context = new project5188Entities();
            EntityList = _context.documenttyperelations.Where(a => a.a_ID == id && !a.IsDeleted).OrderBy(a => a.a_ID).ToList();

            return EntityList;
        }

        public override documenttyperelation GetEntity()
        {
            _context = new project5188Entities();
            Entity = new documenttyperelation();
            return Entity;
        }

        public override void Update()
        {
            _context.SaveChanges();
        }

        public override void Insert()
        {
            _context.AddTodocumenttyperelations(Entity);
            _context.SaveChanges();
            TransactionId = Entity.a_ID;
        }

        public List<documenttyperelation> GetEntityByDocumentTypeId(long documentTypeId)
        {
            _context = new project5188Entities();
            EntityList = _context.documenttyperelations.Where(a => a.b_DocumentTypeParameterValueID == documentTypeId && !a.IsDeleted).OrderBy(a => a.a_ID).ToList();

            return EntityList;
        }

        #endregion
    }
}
